<!--info.less-->
<template>
	<section id="withDrawal">
		<HeaDer :Title='titleData'></HeaDer>
		<section class="iconList" @click="show = true">
			<i class="van-icon van-icon-pending-orders"></i>
		</section>
		<section class="withDrawalWarp">
			<section class="title">
				<h2>账户提现</h2>
			</section>			
			<header>
				<span class="canUser">可用</span>
				<h2>
					<span>{{getData.wallone}}</span>
					<span>USDT</span>
				</h2>
			</header>
			<section class="formWarp">
				<van-cell-group>
					
					<section class="address">
						<span class="title">提币地址</span>
						<van-field  placeholder="输入或长按粘贴地址" type='text' icon="close" v-model='userData.qianbao_url'/>
					</section>
					<section class="num">
						<span class="title">数量</span>
						<van-field  :placeholder="getData.tb_min" v-model='userData.num' type='number' />
						<span class="all" @click="allUsdt">全部</span>
						<p class="alse">可提现最大数量(USDT) : {{getData.tb_max}}</p>
					</section>
					<section class="opwd">
						<span class="title">交易密码</span>
						<van-field  placeholder="请输入交易密码" type='password' icon="close" v-model='userData.tpwd' @click-icon="userData.tpwd=''"/>
						
					</section>
					<section class="mobileCode">
						<span class="title">手机验证码</span>
						<van-field  placeholder="请输入手机验证码" type='text' icon="close" v-model='userData.code'/>
						<input type="button" :value="btnCode.val"  :disabled="btnCode.disabled" class="prompt" @click="getCode">
						
					</section>
				</van-cell-group>
				<section class="btnWarp" @click="submit">
					<section class="btn">
						确定
					</section>
				</section>
			</section>
		</section>
		<van-popup v-model="show" position="right" :overlay="false">
  			<section class="contents">
  				<section class="return" @click="show = false">
  					<i class="van-icon van-icon-arrow-left"></i>
  				</section>
  				<section class="contentsListWarp">
  					<section class="title">
  						<h2>提现记录</h2>
  					</section>
  					<section class="contentsList">
  						<img src="../../../static/img/nolist.png" v-show="contentsList.length == 0"/>
  					</section>
  				</section>
  			
  			</section>
		</van-popup>
		
	</section>
</template>

<script>
	import HeaDer from "../common/header.vue";
	export default {
		data() {
			return {
				show:false,  //列表数据
				contentsList:[],
				btnCode: {
					time: 59,
					disabled: false, //控制点击和不可点击
					val: '获取验证码'
				},
				titleData: {
					name: '',
					flat: 1
				},
				getData:{
					tb_min:'--',  //最小提现
					tb_max:'--',  //最大提现
					wallone:'--'   //账户余额
				},
				userData:{
					mobile:'',
					num: '',
					code: '',
					tpwd: '',
					qianbao_url: ''
				}
			}
		},
		methods: {
			//获得验证码
			getCode(){
				var _this = this;
				if(!_this.userData.qianbao_url){
					_this.$toast('提币地址不能为空!');
					return false;
				}else if(!_this.$public.Ints(_this.userData.num)){
					_this.$toast('提现数量不合法!');
					return false;
				}else if(Number(_this.getData.wallone)<Number(_this.getData.tb_min)){
					
					_this.$toast('提现余额不足');
					return false;
				}else if(Number(_this.userData.num)<Number(_this.getData.tb_min)){
					_this.$toast('最小提现金额为' + _this.getData.tb_min);
					return false;
				}else if(Number(_this.userData.num)>Number(_this.getData.tb_max)){
					_this.$toast('最大提现金额为' + _this.getData.tb_max);
					return false;
				}else if(!_this.$public.pwd(_this.userData.tpwd)){
					_this.$toast('交易密码格式有误');
					return false
					
				}
				//获取验证码
				_this.$public.getCode(sessionStorage.mobile,5,_this);
				
			},
			submit(){
				var _this = this;
				if(!_this.userData.qianbao_url){
					_this.$toast('提币地址不能为空!');
					return false;
				}else if(!_this.$public.Ints(_this.userData.num)){
					_this.$toast('提现数量不合法!');
					return false;
				}else if(Number(_this.getData.wallone)<Number(_this.getData.tb_min)){
					
					_this.$toast('提现余额不足');
					return false;
				}else if(Number(_this.userData.num)<Number(_this.getData.tb_min)){
					_this.$toast('最小提现金额为' + _this.getData.tb_min);
					return false;
				}else if(Number(_this.userData.num)>Number(_this.getData.tb_max)){
					_this.$toast('最大提现金额为' + _this.getData.tb_max);
					return false;
				}else if(!_this.$public.pwd(_this.userData.tpwd)){
					_this.$toast('交易密码格式有误');
					return false					
				}else if(!_this.$public.code(_this.userData.code)){
					_this.$toast('验证码不能为空');
					return false;
				}
				//请求接口
				_this.$public.loading('提交中...',_this);
				_this.$http.post(_this.$host.ti_bi,_this.userData).then(function(data){
					_this.$toast(data.data.msg);
					if(data.data.status == 200) {
						_this.$public.go('security', 200, _this);
					} else {					
						_this.userData.num = '';
						_this.userData.code = '';
						_this.userData.tpwd = '';
						_this.userData.qianbao_url = '';
						
					}
				}).catch(function(){})
			},
			getDatas(){
				var _this = this;
				_this.userData.mobile = sessionStorage.mobile;
				_this.$public.userInfo({
					_this:_this,
					mobile:sessionStorage.mobile,
					sfun:function(data){
						if(data.data.status == 200){						
							_this.getData.tb_min = '最小可提币数量' + data.data.data.tb_min;
							_this.getData.tb_max = data.data.data.tb_max;
							_this.getData.wallone = data.data.data.wallone;
						}
					}
				})
			},
			//点击全部执行函数
			allUsdt(){
				/*
				 todo 
				 1 对比可用余额和最小提现余额如果可用余额小于最小提现余额 提示可提现余额不足
				 2对比可用余额和最大提现余额 如果可用余额大于最大提现余额 显示最大提现余额
				 * */
				var _this = this;
				if(Number(_this.getData.wallone)<Number(_this.getData.tb_min)){
					_this.$toast('提现余额不足');
					return false
				}else if(Number(_this.getData.wallone)>Number(_this.getData.tb_max)){
					_this.userData.num = _this.getData.tb_max;
					return false
				}else {
					_this.userData.num = _this.getData.wallone
				}
			}
		},
		components: {
			'HeaDer': HeaDer

		},
		created: function() {
			var _this = this;
			_this.getDatas();
		}
	}
</script>

<style>

</style>